# submit提交
# import time
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.maximize_window()
# driver.get('http://www.baidu.com')
# driver.find_element(By.XPATH,"//*[@id='kw']").send_keys('CSDN')
# time.sleep(3)
# driver.find_element(By.XPATH,'//*[@id="su"]').submit()
# time.sleep(3)
# driver.quit()
# 获取页面内容
# import time
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.maximize_window()
# driver.get("http://csdn.net")
# title=driver.title
# print(title)
# source_code=driver.page_source
# print(source_code)
# url=driver.current_url
# print(url)
# time.sleep(3)
# driver.quit()
# 调整浏览器尺寸
# import time
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# # 启动并打开指定页⾯
# browser = webdriver.Chrome()
# browser.get("http://www.csdn.net")
# # 窗⼝最⼤化
# browser.maximize_window()
# #停留2秒
# time.sleep(2)
# #窗⼝最⼩化
# browser.minimize_window()
# # 指定窗⼝尺⼨
# browser.set_window_size(300, 500)
# # 关闭页⾯
# import time
# time.sleep(3)
# browser.quit()
# 前进后退
# import time
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.get('http://www.csdn.net')
# driver.maximize_window()
# driver.find_element(By.XPATH,'/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/main[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/ul[1]/li[10]/p[1]').click()
# time.sleep(2)
# driver.back()
# time.sleep(2)
# driver.forward()
# time.sleep(2)
# driver.quit()
# 窗口切换
# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.get('https://www.csdn.net/')
# driver.maximize_window()
# time.sleep(5)
# cwd=driver.current_window_handle
# time.sleep(5)
# driver.find_element(By.XPATH,'//a[1]//span[@class="text word-1"]').click()
# time.sleep(5)
# driver.switch_to.window(cwd)
# time.sleep(5)
# dwhs=driver.window_handles
# print(len(dwhs))
# time.sleep(5)
# driver.quit()
# 鼠标操作
# 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver import ActionChains
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.maximize_window()
# driver.get('https://www.csdn.net')
# time.sleep(2)
# action = ActionChains(driver)
# tag=driver.find_element(By.XPATH,'//*[@id="floor-nav_920"]/div/div/div/div/div[3]/ul/li[7]/p')
# action.move_to_element(tag).click().perform()
# time.sleep(3)
# driver.quit()
# #处理frame内嵌的元素
# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# driver=webdriver.Chrome()
# driver.maximize_window()
# driver.get('D:\\deskbook\\ceshi\\rjcs\\web自动化\\frame内元素操作.html')
# cwd=driver.current_window_handle
# wait=WebDriverWait(driver,20)
# frame=wait.until(EC.presence_of_element_located((By.NAME,"navIframe2")))
# driver.switch_to.frame(frame)
# time.sleep(2)
# search_input=wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="q"]')))
# search_input.send_keys('笔记本')
# search_button=wait.until(EC.element_to_be_clickable((By.XPATH,'//*[@id="J_TSearchForm"]/div[2]/button')))
# search_button.click()
# time.sleep(10)
# driver.back()
# time.sleep(3)
# driver.switch_to.parent_frame()
# time.sleep(5)
# driver.find_element(By.XPATH,'/html/body/div/aside/ul/li[3]/a').click()
# time.sleep(5)
# driver.switch_to.window(cwd)
# time.sleep(5)
# driver.quit()
# 复选框操作
# import time
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver=webdriver.Chrome()
# driver.maximize_window()
# driver.get('D:\deskbook\ceshi\\rjcs\web自动化\复选框.html')
# tag_input=driver.find_elements(By.TAG_NAME,'input')
# selects=['Python','C++']
# for checkbox in tag_input:
#     if checkbox.get_attribute("type")=='checkbox':
#         checkbox_name=checkbox.get_attribute('name')
#         if checkbox_name in selects:
#             checkbox.click()
#             time.sleep(2)
# time.sleep(5)
# driver.refresh()
# time.sleep(5)
# for type_value in tag_input:
#     print(type_value.get_attribute('name'))
#     if type_value.get_attribute('type')=='checkbox':
#         type_value.click()
#         time.sleep(2)
# time.sleep(3)
# driver.quit()
# # 下拉框操作
# from time import sleep
# # 导⼊selenium包
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# # 导⼊Select类
# from selenium.webdriver.support.select import Select
# # 启动并打开指定⻚⾯
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get("D:\\deskbook\\ceshi\\rjcs\\web自动化\\下拉框.html")
# # 定位下拉列表标签,并创建下拉列表对象
# select = Select(driver.find_element(By.TAG_NAME, "select"))
# time.sleep(2)
# select.select_by_value('Python')
# time.sleep(2)
# select.select_by_visible_text('C++')
# time.sleep(2)
# select.select_by_index(0)
# time.sleep(2)
# # TODO 当可选项太多，需要滑动鼠标滚轮的时候也可以直接选中，不需要真正滑动鼠标滚轮
# select.select_by_visible_text('00')
# time.sleep(5)
# 导⼊selenium包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 启动并打开指定⻚⾯
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("D:\deskbook\ceshi\\rjcs\web自动化\弹窗处理.html")
driver.find_element(By.ID, 'alert').click()
time.sleep(2)
alert1 = driver.switch_to.alert
print(alert1.text)
alert1.accept()
time.sleep(2)
driver.find_element(By.ID, 'confirm').click()
time.sleep(2)
confirm = driver.switch_to.alert
print(confirm.text)
confirm.dismiss()
time.sleep(2)
driver.find_element(By.ID, 'prompt').click()
time.sleep(2)
prompt = driver.switch_to.alert
print(prompt.text)
prompt.send_keys('喵喵喵')
time.sleep(2)
prompt.accept()
time.sleep(3)
driver.quit()